<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Trips extends CI_Controller {
	
	 function __construct() {
		parent::__construct();
    $this->load->model('Provincias');
		//$this->load->model('Trip');
	}
	function index()
	{
		
		$this->load->view('layout/header') ; 
    $this->load->view('layout/footer');
	}
	
	function create()
	{
		$data['provincias']=$this->Provincias->get_all();
    
    /*echo "<br>";
    var_dump($data['lat']);
    echo"<br>";
    var_dump($data['log']);*/
		$this->load->view('layout/header') ; 
    $this->load->view('layout/menu');
    $this->load->view('trip/create',$data);
		$this->load->view('layout/footer');
	}
  
  function get_departamentos(){
    //var_dump($this->input);
    /*$this->db->order_by("nombre", "asc"); 
    $query=$this->db->get_where("departamentos",array("provincia_id"=>$provincia_id));
    
    
    $result=FALSE;
    $option="";
    if($query->num_rows()!=0)
    {
      $result=TRUE;
      
      foreach ($query->result() as $row){
        if($option=="")
        {
          $option .="".$row->id."-".$row->nombre."";
        
        }
        else {
          $option .="|".$row->id."-".$row->nombre."";
        }
      }
        
    }
    
    //echo $option;
    */
    echo $json->encode(1);
     
    #$data["json"] = "departamentos: ".$option."" ;
    
    #$this->load->view('json_view', $data);
  }
	
  
  function get_localidades($departamento_id){
    $this->db->order_by("nombre", "asc"); 
    $query=$this->db->get_where("localidades",array("departamento_id"=>$departamento_id));
    
    
    $result=FALSE;
    $option="";
    if($query->num_rows()!=0)
    {
      $result=TRUE;
      
      foreach ($query->result() as $row){
        if($option=="")
        {
          $option .="".$row->id."-".$row->nombre."";
        
        }
        else {
          $option .="|".$row->id."-".$row->nombre."";
        }
      }
        
    }
    
    //echo $option;
    
   // json_encode($result);
    $data["json"] = "localidades: ".$option."" ;//'{"provincia_id":'.$provincia_id.',"options":'.$option.'}';
    //$data['provincia_id'] = '{ssfully."}';
    $this->load->view('json_view', $data);
  }
	
  function geoposition(){
    echo var_export(unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])));
    echo "<br> --- <br> ---<br>";
    $get_pos=unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])) ;
    var_dump($get_pos['geoplugin_latitude']);//unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.$_SERVER['REMOTE_ADDR'])) );
  }
 
  
}